import * as echarts from 'echarts';
type EChartsOption = echarts.EChartsOption;
import { proReport } from "@/api/report"
import { message } from 'antd';

export default async function barOption7(myChart: echarts.ECharts) {
    myChart && myChart.showLoading({ text: "", color: "#8870eb" })
    let data = []
    let data2 = []
    let activeName = []
    const res = await proReport()
    myChart&&myChart.hideLoading()
    if (res.code == 200) {
        data = res.data.map((item:any)=>item.sales)
        activeName = res.data.map((item:any) => item.name)
        data2 = res.data.map((item:any) => item.saleroom)
    } else {
        message.error("获取信息失败")
    }
    return {
        title: {
            text: '产品销量报表',
            left: 'center'
        },
        xAxis: {
            type: 'category',
            data: activeName || [],
            name: "产品名称"
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        legend: {
            data: ['销量', '销售额'],
            left:10
          },
        yAxis: [
            {
                type: 'value',
                name:'销量',
                position:'left',
            },
            {
                type: 'value',
                name:'销售额',
                position:'right'
            },
        ],
        grid:{
           top:150
        },
        series: [
            {
                name:'销量',
                data:  data||[],
                type: 'bar',
                yAxisIndex:0,
                label:{
                    show:true,
                    position:'top'
                }
            },
            {
                data:  data2||[],
                type: 'bar',
                name:'销售额',
                yAxisIndex:1,
                label:{
                    show:true,
                    position:'top'
                    
                }
            }
        ]
    } as EChartsOption;
}

